<?php defined('SYSPATH') or die('No direct script access.');

/**
 *质检入库控制器
 *
 * @package  qcwo
 * @author taj
 *
 */
class Controller_Qcwo extends Controller_Admin{
    /**
     *正常扫描入库人的权限
     *
     */
    public function before(){
        try {
            ACL::Required('administer qcwo');
        } catch (HTTP_Exception_403 $e) {
            Message::error('sorry，你没有权限进这个目录');
            $this->request->redirect(URL::base(true));
        }

        parent::before();
    }

    /**
     *扫描入库的默认界面
     *
     */
    public function action_index(){
        $this->title = __('扫描入库');

        $view = View::factory('inventory/qcwo');

        $this->response->body($view);

    }

    /**
     *通过条件扫描入库操作功能
     *
     */
    public function action_selectrecieve(){
        $this->title = __('扫描入库');

        $arr = explode(':', trim($_GET['reo']));
        $results = '';

        if ((count($arr)) != 3) {
            $notice = '扫描的标签不对，不是质检详情单号';
        } else if ($arr[2] == 'A') {//判断是否是质检合格的入库，质检合格的详情单号
            if ($arr[1] == '') {
                $notice = '扫描的质检详情单号为空，无法入库';
            } else {
                $sel_wo = qcwo::select_wo($arr[1], 0);
                if ($sel_wo->id != '') {
                    $notice = '该质检详情单已入erp系统，不能重复扫描入库';
                } else {
                    $select_qcd = qcwo::selectreo($arr[1], 10);//查询对应的质检详情数据
                    if (is_array($select_qcd)) {
                        $insert_wo = qcwo::insert_wo($select_qcd);//将对应的质检详细合格数据插入入库表
                        $notice = $insert_wo;
                        if ($notice == 'ok') {
                            $results = qcwo::select_wo($arr[1], 0);//查询对应的入库结果

                        }
                    } else {
                        $notice = $select_qcd;
                    }
                }
            }
        } else if ($arr[2] == 'B') {//判断是不合格的质检折让入库
            if ($arr[1] == '') {
                $notice = '扫描的不合格质检详情单号为空，无法入库';
            } else {
                $sel_wo = qcwo::select_wo($arr[1], 1);
                if ($sel_wo->id != '') {
                    $notice = '不合格质检详情单号已入erp系统，不能重复扫描入库';
                } else {
                    $notice = qcwo::insert_wo($arr[1]);
                    if ($notice == 'ok') {
                        $results = qcwo::select_wo($arr[1], 1);//查询对应的入库结果
                    }
                }
            }

        }

        $view = View::factory('inventory/qcwo')
            ->set('notice', $notice)
            ->set('results', $results);

        $this->response->body($view);

    }

    public function action_test(){
        $reo = 'BL1084:1:B';
        $arr = explode(':', $reo);
        print_r($arr);
        echo count($arr);

    }

}
